
bash /data/sync2prod/only-sync.sh


taskLog=/data/sync2prod/$deployment
echo "同步到 %taskLog并部署！"
cd $taskLog

touch dep-task.log

host=https://test.huatuocloud.com/api/mp-admin-api
#host=http://192.168.2.117:8001

imageNameVersion="$language/$deployment:$imageVersion"

echo "$imageNameVersion" > dep-task.log


function setImageVersion(){
  if [ "$isNew" == "true" ]; then
        echo "新 $language Job"
        return
  else

   echo -e "curl -X POST -o curl-result.txt -s -w  %{http_code} --max-time 6 --retry 3 $host/ops/k8s/deployment/sync-prod-version?admin-token=thsx.123\&namespace=default\&=language=$language\&deployment=$deployment\&version=$imageVersion"
   code=$(curl -X POST -o curl-result.txt -s -w  %{http_code} --max-time 6 --retry 3 $host/ops/k8s/deployment/sync-prod-version?admin-token=thsx.123\&namespace=default\&=language=$language\&deployment=$deployment\&version=$imageVersion)

    if [ "$code" == "000" ]; then
        echo "网络错误，请重试！"
        return 3;
    elif [ "$code" == "200"  ] &&  grep -q '"code":0' curl-result.txt ; then
        echo -e "\n"`date "+%Y-%m-%d %H:%M:%S"` "部署镜像 $deployment 成功!"
        cat curl-result.txt
    else
        echo -e "\n"`date "+%Y-%m-%d %H:%M:%S"` "部署镜像 $deployment 失败!!! 返回: $code"
        cat curl-result.txt
        return 1
    fi
  fi
}


setImageVersion | tee -a dep-task.log

echo -e "\n[deploy done]" | tee -a dep-task.log

cat dep-task.log
